package com.example.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import static org.junit.Assert.*;

import com.google.common.base.Predicate;

public class InternalPage extends Page {
	
	
	@FindBy (xpath ="//div[@id='wrapper']/header/div/div/ul/li/a")
	public  WebElement English;
	
	@FindBy (xpath ="//li[2]/a")
	public  WebElement Nederlands;
	
	@FindBy (xpath ="//div[@id='wrapper']/header/div/nav/ul/li/a")
	public  WebElement Home;
	
	
	@FindBy (xpath ="//div[@id='wrapper']/header/div/nav/ul/li[2]/a")
	public WebElement Myprofile;
	
	
	@FindBy (xpath ="//div[@id='wrapper']/header/div/nav/ul/li[3]/a")
	public  WebElement UserManager;
	
		
	@FindBy (xpath ="//div[@id='wrapper']/header/div/nav/ul/li[4]/a")
	public  WebElement LogOut;
	

	@FindBy (xpath ="//div[@id='wrapper']/header/div/a/h1")
	public  WebElement MyCollection;
	
	
	public void userName(String userName, String password) {
		driver.findElement(By.id("username")).clear();
	    driver.findElement(By.id("username")).sendKeys(userName);
	    driver.findElement(By.name("password")).clear();
	    driver.findElement(By.name("password")).sendKeys(password);
	    driver.findElement(By.name("submit")).click();
	}
	
	
	public void newUser(String nameNewUser, String emailNewUser, String password1, String password2) {
		driver.findElement(By.linkText("User management")).click();
		
		driver.findElement(By.id("username")).clear();
	    driver.findElement(By.id("username")).sendKeys(nameNewUser);
	    driver.findElement(By.name("email")).clear();
	    driver.findElement(By.name("email")).sendKeys(emailNewUser);
	    driver.findElement(By.id("password")).clear();
	    driver.findElement(By.id("password")).sendKeys(password1);
	    driver.findElement(By.id("password2")).clear();
	    driver.findElement(By.id("password2")).sendKeys(password2);
	    driver.findElement(By.name("submit")).click();
	}
	
	
	public void GotoUserManagement () {
		driver.findElement(By.linkText("User management")).click();
	}
	@Override
	void tryToOpen() {
		MyPageFactory.getPage(driver, InternalPage.class).userName("admin","admin");
	}
		
		public boolean isOnThisPage() {
			return LogOut.isDisplayed();
	}
	
		public void logout (){
		LogOut.click();
		
		}


		
}
